package com.edu.zju.scs.panacea.controller.plan;

import com.edu.zju.scs.panacea.entity.BaseResult;
import com.edu.zju.scs.panacea.entity.plan.Industry;
import com.edu.zju.scs.panacea.service.plan.IndustryService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @Author: Yue Liang
 * @Date: 2018-12-24 10:39
 */

@Controller
@EnableAutoConfiguration
public class IndustryController {

    @Autowired
    private IndustryService industryService;

    @ResponseBody
    @ApiOperation(value="根据id查询某个行业", notes="根据id查询某个行业")
    @RequestMapping(value = "/industry/{id}", method = RequestMethod.GET)
    public BaseResult getIndustry(@PathVariable Long id) {
        return industryService.getIndustry(id);
    }

    @ResponseBody
    @ApiOperation(value="查询所有行业", notes="查询所有行业")
    @RequestMapping(value = "/industry/all", method = RequestMethod.GET)
    public BaseResult getAllIndustry() {
        return industryService.getAllIndustry();
    }

    @ResponseBody
    @ApiOperation(value="根据ID删除行业", notes="根据ID删除行业")
    @RequestMapping(value = "/industry/deletion/{id}", method = RequestMethod.GET)
    public BaseResult deleteIndustry(@PathVariable Long id) {
        return industryService.deleteIndustry(id);
    }

    @ResponseBody
    @ApiOperation(value="新增行业", notes="新增行业")
    @RequestMapping(value = "/industry/new", method = RequestMethod.POST)
    public BaseResult addIndustry(
            @ApiParam("行业名称") @RequestParam(value = "name") String name,
            @ApiParam("行业所需资质") @RequestParam(value = "qualifications") List<String> qualifications) {
        Industry industry = new Industry();
        industry.setName(name);
        industry.setQualifications(qualifications);
        return industryService.addIndustry(industry);
    }

    @ResponseBody
    @ApiOperation(value="修改行业信息", notes="修改行业信息")
    @RequestMapping(value = "/industry/edit", method = RequestMethod.POST)
    public BaseResult editIndustry(
            @ApiParam("ID") @RequestParam(value = "id") Long id,
            @ApiParam("行业名称") @RequestParam(value = "name") String name,
            @ApiParam("行业所需资质") @RequestParam(value = "qualifications") List<String> qualifications) {
        Industry industry = new Industry();
        industry.setId(id);
        industry.setName(name);
        industry.setQualifications(qualifications);
        return industryService.editIndustry(industry);
    }
}
